﻿using System;
using SubSonic.Repository;
using Webbness.Mvc.Properties;

namespace Webbness.Mvc.SubSonic
{
    public class Repository
    {
        private static SimpleRepository SimpleRepo;
        private static SimpleRepositoryOptions options;
        private static string connectionName;

        public static String ConnectionName
        {
            get { return connectionName; }
        }

        public static SimpleRepositoryOptions MigrationOptions
        {
            get { return options; }
        }

        public static SimpleRepository Repo
        {
            get
            {
                if (SimpleRepo == null)
                {
                    options = Settings.Default.MigrationOptions;
                    connectionName = Settings.Default.ConnectionName;
                    SimpleRepo = new SimpleRepository(connectionName, options);
                }
                return SimpleRepo;
            }
        }

        public static T Get<T>(object key) where T : class, new()
        {
            return Repo.Single<T>(key);
        }
    }
}